package com.changgou.order.config;

import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.BindingBuilder;
import org.springframework.amqp.core.DirectExchange;
import org.springframework.amqp.core.Exchange;
import org.springframework.amqp.core.Queue;
import org.springframework.amqp.core.QueueBuilder;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @Author: HuxiWang
 * @Date: Create in 20:49 2021/1/29
 * @Description:
 */
@Configuration
public class QueueConfig {

    // 延迟队列
    public static final String QUEUE_MESSAGE_DELAY = "queue.message.delay";

    @Bean
    public Queue orderDelayQueue() {
        return new Queue("orderDelayQueue", true);
    }

    @Bean
    public Queue orderListenerDelay() {
        return QueueBuilder.durable("orderListenerDelay")
                // 死信交换机
                .withArgument("x-dead-letter-exchange", "")
                // 死信routing-key
                .withArgument("x-dead-letter-routing-key", "orderListenerDelay")
                .build();
    }

    // 交换机
    @Bean
    public Exchange orderListenerExchange() {
        return new DirectExchange("orderListenerExchange");
    }

    // 绑定
    @Bean
    public Binding orderListenerBinding(Queue orderListenerDelay, Exchange orderListenerExchange) {
        return BindingBuilder
                .bind(orderListenerDelay)
                .to(orderListenerExchange)
                .with("orderListenerDelay")
                .noargs();
    }

}












